package jdbctest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by Administrator on 2017/9/11.
 */
public class InsertTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //连接数据库
        Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3307/test","root","123456");
        //获得statement
        Statement statement=conn.createStatement();
        //执行sql(表中插入一条记录)
        String sql="insert into tablename1(id,name,sb) values(5,'死宅','233')";
        statement.executeUpdate(sql);
        //关闭资源
        statement.close();
        conn.close();
    }
}
